//
//  LabBaseController.m
//  OCDemo
//
//  Created by BH on 15/9/25.
//  Copyright © 2015年 baohan. All rights reserved.
//

#import "LabBaseController.h"
#import "Masonry.h"

@interface LabBaseController ()

@end

@implementation LabBaseController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    NSString *clsName = NSStringFromClass([self class]);
    self.title = [clsName substringToIndex:clsName.length-@"Controller".length];
    
    [self.view addSubview:self.label];
    [self.view addSubview:self.button];
    
    [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@((self.view.frame.size.width-150)/2));
        make.top.equalTo(self.view).offset(74);
        make.width.equalTo(@150);
        make.height.equalTo(@40);
    }];
    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(10);
        make.right.equalTo(self.view).offset(-10);
        make.top.equalTo(self.button.mas_bottom).offset(20);
        make.height.equalTo(@100);
    }];
    
    //文字改变
    [self labelChange];
}

-(void)labelChange
{
    static int i = 0;
    
    int result = i % [self resultCount];
    
    [self.button setTitle:[NSString stringWithFormat:@"Change(Now:%d)",result] forState:UIControlStateNormal];
    
    [self changeToResult:result];
    
    i++;
}

#pragma mark - getter
-(MLLabel *)label
{
    if (!_label) {
        _label = [[self labelClass] new];
        _label.backgroundColor = [UIColor colorWithWhite:0.920 alpha:1.0];
    }
    
    return _label;
}

-(UIButton *)button
{
    if (!_button) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"Change" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [button.titleLabel setFont:[UIFont systemFontOfSize:15.0]];
        button.backgroundColor = [UIColor darkGrayColor];
        [button addTarget:self action:@selector(labelChange) forControlEvents:UIControlEventTouchUpInside];
        
        _button = button;
    }
    
    return _button;
}

#pragma mark - ovveride
-(Class)labelClass
{
    return [MLLabel class];
}

-(NSInteger)resultCount
{
    return 1;
}

-(void)changeToResult:(NSInteger)result
{
    
}

@end
